﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace serva
{
	/// <summary>
	/// Lógica de interacción para Panel_Inventario.xaml
	/// </summary>
	public partial class Panel_Inventario : UserControl
	{
		public List<Componente> ListInventario = new List<Componente>();
        public List<Unidad> ListUnidades = new List<Unidad>();
		Componente actual = new Componente();
		
		public Panel_Inventario()
		{
			this.InitializeComponent();
            Cargar();
		}

		private void grid_Inventario_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
		{
            try
            {
                if (actual == null)
                {
                    return;
                }

                actual = (Componente)grid_Inventario.SelectedItem;
                labelNombre.Content = actual.Nombre.ToString();
                labelCodigo.Content = actual.Codigo.ToString();

            }
            catch (InvalidCastException)
            {             
                return;
            }           
                
          
		}

		private void btnAdd_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			ListInventario.Add(new Componente());
            grid_Inventario.Items.Refresh();
        }

        public void Cargar()
        {
            grid_Inventario.ItemsSource = ListInventario;
            grid_Inventario.ColumnWidth = 116;
            CboxUnidad.ItemsSource = ListUnidades;
            CboxUnidad.DisplayMemberPath = "Nombre";
        }

        private void CboxUnidad_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            actual.u = (Unidad)CboxUnidad.SelectedItem;
            grid_Inventario.Items.Refresh();
        }
	}
}